<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.css" rel="stylesheet" media="screen">
</head>

<body>
<div style="padding:5px; margin:0px;">
    <ul class="breadcrumb" style="  margin:0px; ">
        <li>
            <a href="#">商品管理</a>
        </li>
        <li>增加商品</li>
    </ul>
</div>

<form action="${pageContext.request.contextPath}/goods?method=add" method="post" accept-charset="UTF-8" enctype="application/x-www-form-urlencoded" class="form-horizontal">
    <!--开始 -->
    <div class="row">
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-3 control-label">商品名称</label>
                <div class="col-sm-9">
                    <input type="text" name="goodName" class="form-control input-sm" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商品类型</label>
                <div class="col-sm-4">
                    <select id="category" name="categoryId" class="form-control">
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">商品价格</label>
                <div class="col-sm-9">
                    <input type="text" name="price" class="form-control input-sm" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商品库存</label>
                <div class="col-sm-9">
                    <input type="text" name="stock" class="form-control input-sm" />
                </div>
            </div>

        </div>
    </div>
    <!--结束 -->
    <div class="row">
        <div class="col-sm-3 col-sm-offset-2">
            <input type="submit" class="btn btn-success" value="提交" />
            <a class="btn btn-warning" href="${pageContext.request.contextPath}/goods?method=list">返回上一级</a>
        </div>
    </div>
</form>
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/alert.min.js"></script>
<script type="text/javascript">
    $(function(){
        $("#category").append("<option selected='selected'>--请选择商品类型--</option>");
        // Ajax获取商品类型信息，再通过DOM编程设置select
        $.post("${pageContext.request.contextPath}/category?method=findAllCategory",{},function(data){
            for(var i=0;i<data.length;i++){
                $("#category").append("<option value="+data[i].categoryId+">"+data[i].categoryName+"</option>");
            }
        },"json");//指定返回类型为json
    });
</script>
</body>

</html>
